//============================================================================
// Name        : dp.cpp
// Author      : shuai
// Version     :
// Copyright   : This project is free to use.
// Description : This is a tool used to parse SUMO detector output file (.xml) to
//              data format (.csv)
//              
//              For example:
//              Input file (.xml):
//                  <detector>
//                      <interval begin="0.00" end="300.00" id="111_0" 
//                          nVehContrib="0" flow="0.00" occupancy="0.00" 
//                          speed="-1.00" length="-1.00" nVehEntered="0"/>
//                      <interval begin="300.00" end="600.00" id="111_0" 
//                          nVehContrib="0" flow="0.00" occupancy="0.00" 
//                          speed="-1.00" length="-1.00" nVehEntered="0"/>
//                  </detector>
//              Output (.csv):
//                  begin;end;id;nVehContrib;flow;occupancy;speed;length;nVehEntered
//                  0.00;300.00;111_0;0;0;0;-1;-1;0
//                  300.00;600.00;111_0;0;0;0;-1;-1;0
//============================================================================

#include <iostream>
#include <vector>
#include "SOPDetectorTool.h"
#include "IntToString.h"

int main(int argc, char * argv[])
{
	std::vector<std::string> inputs;

	std::string pre = "/home/shuai/workspace/sumo/c_s/2_2/data/detector_";
	std::string suff = ".data";
   
    std::vector<std::string> detectors;
    detectors.push_back("111");
    detectors.push_back("112");
    detectors.push_back("113");
    detectors.push_back("121");
    detectors.push_back("122");
    detectors.push_back("123");
    detectors.push_back("211");
    detectors.push_back("212");
    detectors.push_back("213");
    detectors.push_back("221");
    detectors.push_back("222");
    detectors.push_back("223");
    
    // Detectors from 111_0 to 111_9
    std::string fileStr = "";
    std::string curFile = "";
    for(size_t i = 0; i < detectors.size(); i++)
    {
        for(int j = 0; j < 10; j++)
        {
            fileStr = detectors.at(i) + '_' + IntToString(j);
            curFile = pre +  fileStr + suff; 
            inputs.push_back(curFile);
        }
    }

	std::size_t size = inputs.size();
#ifdef DEBUG
	std::cout << "size = " << size << std::endl;
#endif
	SOPDetectorTool * tool;
	for(std::size_t i = 0; i < size; i++)
	{
#ifdef DEBUG
		std::cout << "i = " << i << std::endl;
#endif
		tool = new SOPDetectorTool();
		tool->SetInputFile(inputs.at(i) + ".xml");
		tool->SetOutputFile(inputs.at(i) + ".csv");

		tool->Parse();

		if(tool != NULL)
		{
			delete tool;
			tool = NULL;
#ifdef DEBUG
			std::cout << "delete tool" <<std::endl;
#endif
		}
	}

	return 0;
}
